package com.shlh.saas.util;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

@Component
public class CompanyDataSource {

    private final DataSource dataSource;

    public CompanyDataSource() {
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl("jdbc:mysql://192.168.1.190:3306/zoominfo");
        ds.setUsername("root");
        ds.setPassword("qazwsx123");
        ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
        // 最大连接数等
        ds.setMaximumPoolSize(10);
        this.dataSource = ds;
    }

    public DataSource dataSource() {
        return dataSource;
    }
    
    /**
     * 获取指定表的数据库连接
     * @param tableName 表名
     * @return 数据库连接
     * @throws SQLException 如果获取连接失败
     */
    public Connection getConnectionForTable(String tableName) throws SQLException {
        return dataSource.getConnection();
    }
}
